Skip to content

ASoC: SOF: Intel: hda: make sure the DMA is started/stopped by checking the RUN bit - #997

Merged
plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
zhuyingjiang:topic/make-sure-the-RUN-bit-is-set
Jun 11, 2019
Merged

plbossart merged 2 commits into
thesofproject:topic/sof-devfrom
zhuyingjiang:topic/make-sure-the-RUN-bit-is-set

Conversation

@zhuyingjiang

Copy link
Copy Markdown

As per the HW recommendation, after setting the RUN bit (start as 1, stop as 0), software must read the bit back to make sure the bit is right set, before modifying related control registers/re-starting the DMA engine.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to fix code style and need to fix assignment of the additional 'run' variable.

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
SOF_HDA_CL_DMA_SD_INT_MASK, 0x0);

ret =
snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better you have the function on the previous line. Try to see if you can fix the 80 char issue otherwise it's ok to not follow that rule.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

Comment thread sound/soc/sof/intel/hda.h Outdated

#define HDA_DSP_STREAM_RESET_TIMEOUT 300
#define HDA_DSP_CL_TRIGGER_TIMEOUT 300
#define HDA_DSP_STREAM_TRIGGER_TIMEOUT 300

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same as legacy or Skylake, if yes add a comment. This looks like copy-paste and not an intentional definition

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Skylake, it is hard code. OK, I will add a comment to it.

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
int ret, timeout = HDA_DSP_STREAM_RESET_TIMEOUT;
u32 val, mask;
u32 val, mask, run;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one variable per line please

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
SOF_HDA_SD_CTL_DMA_START, 0);

ret =
snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, function on previous line

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
int sd_offset = SOF_STREAM_SD_OFFSET(hstream);
int ret, timeout = HDA_DSP_STREAM_RESET_TIMEOUT;
u32 val, mask;
u32 val, mask, run;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run is not set anywhere, have you actually tested this code?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the snd_sof_dsp_read_poll_timeout is a #define defined by @kv2019i :
set by line:
(val) = snd_sof_dsp_read(sdev, bar, offset); \

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
ret =
snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
sd_offset, run,
((run & SOF_HDA_SD_CTL_DMA_START)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is run set in this patch?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the snd_sof_dsp_read_poll_timeout is a #define defined by @kv2019i :
set by line:
(val) = snd_sof_dsp_read(sdev, bar, offset); \

@zhuyingjiang
zhuyingjiang force-pushed the topic/make-sure-the-RUN-bit-is-set branch from 00a4931 to c6f9ad4 Compare June 3, 2019 06:38
@zhuyingjiang
zhuyingjiang requested a review from plbossart June 3, 2019 06:38
@zhuyingjiang

Copy link
Copy Markdown
Author

@plbossart Updated, with 2 lines exceed 80 chars.

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit language: "to make sure the bit is right set" -> "to make sure the bit is set right"

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks functionally good. A few editorial comments on commit message, doxygen description and line-wrapping.

Comment thread sound/soc/sof/intel/hda-stream.c Outdated
sd_offset, run, ((run &
SOF_HDA_SD_CTL_DMA_START)
==
SOF_HDA_SD_CTL_DMA_START),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhuyingjiang Having just "==" on the line is not readable anymore. I'd recommend not aligning to the opening brace and having a bit more space for the arguemnts. E.g. see call to snd_sof_dsp_read_poll_timeout() in hda-dsp.c:hda_dsp_core_power_down().

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kv2019i OK, thanks!

Comment thread sound/soc/sof/intel/hda.h Outdated
* Timeout in us, for setting the stream RUN bit, during
* start/stop the stream. The time calculate the difference
* between write the RUN bit, and read the RUN bit to make
* sure it is set.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:
""Timeout in us, for setting the stream RUN bit, during
start/stop the stream. The timeout expires if new RUN bit
value cannot be read back within the specified time.""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

@zhuyingjiang
zhuyingjiang force-pushed the topic/make-sure-the-RUN-bit-is-set branch from c6f9ad4 to fdcea3e Compare June 4, 2019 01:52
@zhuyingjiang

Copy link
Copy Markdown
Author

Updated, thanks @kv2019i for the suggestions!

@zhuyingjiang
zhuyingjiang requested a review from kv2019i June 4, 2019 01:55

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Almost there. One change req to the second commit still:

-During clear the stream status when setting HW parameters,
-the RUN bit must be read back as 0 after setting to 0, to
-make sure the stream is stopped.
+Beforing clearing stream statuses, ensure RUN bit update has taken
+effect by reading the value back.

Otherwise looks good to go!

@zhuyingjiang
zhuyingjiang force-pushed the topic/make-sure-the-RUN-bit-is-set branch from fdcea3e to dd3e3a9 Compare June 5, 2019 02:16
@zhuyingjiang

Copy link
Copy Markdown
Author

@kv2019i Updated, thanks!

@zhuyingjiang
zhuyingjiang requested a review from kv2019i June 5, 2019 04:22
kv2019i
kv2019i previously approved these changes Jun 5, 2019

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thank you!

sd_offset, run, ((run &
SOF_HDA_SD_CTL_DMA_START)
== 0x0),
HDA_DSP_REG_POLL_INTERVAL_US,

@lgirdwood lgirdwood Jun 5, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

((run & SOF_HDA_SD_CTL_DMA_START) == 0x0), is a lot for a parameter, it's always better to define the variable on an earlier line e.g.
run_value = !(run &SOF_HDA_SD_CTL_DMA_START)
This can be fixed incrementally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @lgirdwood please add an intermediate variable and simplify this.

@zhuyingjiang zhuyingjiang Jun 10, 2019 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood @plbossart @kv2019i
The snd_sof_dsp_read_poll_timeout is a macro #define, not a really function, if using predefined variable as @lgirdwood suggested, the result should be not the same. Because the #define need first get the value of "run", and then the run & SOF_HDA_SD_CTL_DMA_START can be calculated.
@kv2019i Do you agree?

Another solution maybe define a macro for run & SOF_HDA_SD_CTL_DMA_START, as:
1):
#define RUN_VALUE ((run) & SOF_HDA_SD_CTL_DMA_START)

and use RUN_VALUE == SOF_HDA_SD_CTL_DMA_START and RUN_VALUE == 0 as the parameter.

or
2):
#define RUN_DMA_START (((run) & SOF_HDA_SD_CTL_DMA_START) == SOF_HDA_SD_CTL_DMA_START)
#define RUN_DMA_STOP (((run) & SOF_HDA_SD_CTL_DMA_START) == 0x0)

and use as:

		ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
						sd_offset, run, RUN_DMA_START,
						HDA_DSP_REG_POLL_INTERVAL_US,
						HDA_DSP_STREAM_RUN_TIMEOUT);

What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhuyingjiang I'm ok with the original as well -- this is used elsewhere in the codebase already. I'm not sure how much this helps readability to define more macros. Upto @plbossart and @lgirdwood who made the review comments.

One more option is to use a local variable to describe the mask only:

                u32 dma_start = SOF_HDA_SD_CTL_DMA_START;
		ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_HDA_BAR,
						sd_offset, run, !(run & dma_start),
						HDA_DSP_REG_POLL_INTERVAL_US,

But yeah, the improvement is limited.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this update much better...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks @kv2019i , I will update with this solution.

lgirdwood
lgirdwood previously approved these changes Jun 5, 2019

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but please don't put large/complex params as function args.

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor changes needed

sd_offset, run, ((run &
SOF_HDA_SD_CTL_DMA_START)
== 0x0),
HDA_DSP_REG_POLL_INTERVAL_US,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with @lgirdwood please add an intermediate variable and simplify this.

Comment thread sound/soc/sof/intel/hda.h
* start/stop the stream. The timeout expires if new RUN bit
* value cannot be read back within the specified time.
*/
#define HDA_DSP_STREAM_RUN_TIMEOUT 300

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still doesn't tell me where this value comes from, is this a hardware recommendation or 'same as the other drivers'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plbossart it is "same as the other drivers"

@zhuyingjiang
zhuyingjiang requested review from kv2019i, lgirdwood and plbossart and removed request for kv2019i, lgirdwood and plbossart June 10, 2019 07:11
@zhuyingjiang
zhuyingjiang dismissed stale reviews from lgirdwood and kv2019i via c07c69f June 11, 2019 02:16
@zhuyingjiang
zhuyingjiang force-pushed the topic/make-sure-the-RUN-bit-is-set branch from dd3e3a9 to c07c69f Compare June 11, 2019 02:16
@zhuyingjiang

Copy link
Copy Markdown
Author

@plbossart @lgirdwood @kv2019i Updated, thanks!

As per the HW recommendation, after setting the RUN bit
(start as 1, stop as 0), software must read the bit back
to make sure the bit is set right, before modifying related
control registers/re-starting the DMA engine.

Signed-off-by: Zhu Yingjiang <yingjiang.zhu@linux.intel.com>
…ream status

Beforing clearing stream statuses, ensure RUN bit update has taken
effect by reading the value back.

Signed-off-by: Zhu Yingjiang <yingjiang.zhu@linux.intel.com>
@zhuyingjiang
zhuyingjiang force-pushed the topic/make-sure-the-RUN-bit-is-set branch from c07c69f to 16dc2ab Compare June 11, 2019 02:27
@zhuyingjiang zhuyingjiang mentioned this pull request Jun 11, 2019
5 of 7 tasks

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, need 2nd reviewer

@plbossart
plbossart merged commit 3db5c23 into thesofproject:topic/sof-dev Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants